<template>
  <div class="op-btns" :style="{top:`${styleTop}px`,right:`${styleRight}px`,'border-radius':`${borderRadius}px`}">
    <div :style="{'border-radius':`${borderRadius}px`}" v-if="showMin" class="iconfont icon-min" @click="minimize()" title="最小化"></div>
    <div :style="{'border-radius':`${borderRadius}px`}" v-if="showMax" :class="['iconfont',isMax?'icon-maximize':'icon-max']"  :title="isMax? '还原':'最大化'" @click="maximize()"></div>
    <div :style="{'border-radius':`${borderRadius}px`}" v-if="showClose" class="iconfont icon-close"  title="关闭" @click="close()"></div>
  </div>

</template>

<script setup>
import { ref, reactive, getCurrentInstance,nextTick, onMounted} from 'vue'
import { useRouter, useRoute } from 'vue-router'
const { proxy } = getCurrentInstance()
const router = useRouter()
const route = useRoute()

const props=defineProps({
    showMin:{
      type:Boolean,
      default:true
    },

    showMax:{
      type:Boolean,
      default:false
    },

     showClose:{
        type:Boolean,
        default:true
    },
     closeType:{
        type:Number,
        default:0 //0:关闭当前窗口 1:隐藏窗口
    },

    styleTop:{
      type:Number,
      default:0
    },

     styleRight:{
      type:Number,
      default:0
    },

    borderRadius:{
      type:Number,
      default:0
    },

    forceClose:{
       type:Boolean,
       default:false
    },

})



const winop =(action,data)=>{
     window.electron.ipcRenderer.send("winTitleOp",{action,data});
}

const close =()=>{
  winop("close",{closeType:props.closeType,forceClose:props.forceClose})
}

const custclose = ()=>{
    winop("close",{closeType:props.closeType,forceClose:true})
}

const minimize =()=>{
    winop("minimize")
}



const maximize =()=>{

   if(isMax.value){
     winop("unmaximize")
   }else{
     winop("maximize")
   }

}


onMounted(()=>{
   isMax.value=false;
   window.electron.ipcRenderer.on('winIsMax',(e,result)=>{
       isMax.value = result;
   })
})


const isMax = ref(true)

defineExpose({
  custclose
})




</script>

<style lang="scss" scoped>
.op-btns{
    position: absolute;
    -webkit-app-region: no-drag;
    display: flex;
    .iconfont{
      color:var(--text);
      padding:6px;
      cursor: pointer;
      &:hover{
        background: #ddd;
      }
    }
    .icon-close{
      &:hover{
        background: #fa4e32;
        color: #fff;
      }
    }
    .win-top{
      color: var(--pink);
    }


}

</style>
